Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
buffer-crc32
Advanced tools
The buffer-crc32 package is a Node.js module for calculating CRC32 checksums of buffers. It's a fast and simple utility for generating checksums of data, which can be useful for verifying the integrity of data being transferred over a network or stored.
Calculate CRC32 checksum
This feature allows you to calculate the CRC32 checksum of a given buffer. The code sample demonstrates how to calculate the checksum of a 'Hello World' string.
const crc32 = require('buffer-crc32');
const buffer = Buffer.from('Hello World');
const checksum = crc32(buffer);
console.log(checksum.toString('hex'));
Update existing checksum with new data
This feature enables you to update an existing checksum with new data. The code sample shows how to calculate the checksum for 'Hello', then update it with ' World' to get the checksum for 'Hello World'.
const crc32 = require('buffer-crc32');
let checksum = crc32(Buffer.from('Hello'));
checksum = crc32(Buffer.from(' World'), checksum);
console.log(checksum.toString('hex'));
The 'crc' package offers a wider range of CRC algorithms, including CRC32. It provides more flexibility compared to buffer-crc32 but might be slightly more complex to use for simple CRC32 calculations.
This package is designed for streaming data and calculating CRC32 checksums on the fly. It's more suited for scenarios where data is being processed in streams, compared to buffer-crc32 which works on buffers.
crc32 that works with binary data and fancy character sets, outputs buffer, signed or unsigned data and has tests.
Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix
npm install buffer-crc32
var crc32 = require('buffer-crc32');
// works with buffers
var buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00])
crc32(buf) // -> <Buffer 94 5a ab 4a>
// has convenience methods for getting signed or unsigned ints
crc32.signed(buf) // -> -1805997238
crc32.unsigned(buf) // -> 2488970058
// will cast to buffer if given a string, so you can
// directly use foreign characters safely
crc32('自動販売機') // -> <Buffer cb 03 1a c5>
// and works in append mode too
var partialCrc = crc32('hey');
var partialCrc = crc32(' ', partialCrc);
var partialCrc = crc32('sup', partialCrc);
var partialCrc = crc32(' ', partialCrc);
var finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>
This was tested against the output of zlib's crc32 method. You can run
the tests withnpm test
(requires tap)
https://github.com/alexgorbatchev/node-crc, crc.buffer.crc32
also
supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).
MIT/X11
FAQs
A pure javascript CRC32 algorithm that plays nice with binary data
The npm package buffer-crc32 receives a total of 13,749,959 weekly downloads. As such, buffer-crc32 popularity was classified as popular.
We found that buffer-crc32 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.